#!/usr/bin/env bash

function checkBuild() {
    if [[ ! -e "build/fder" || ! -e "build/deployment" ]]; then
        echo "请先进行编译"
        exit 1;
    fi
}

if [[ $1 == "" || $1 == "build" ]]; then
    rm /build/* -rf
    go build -o build/fder main/deployment.go
    go build -o build/deployment main/deployment.go
    md5sum build/fder
    md5sum build/deployment
elif [[ $1 == "install" ]]; then
    checkBuild
    cp -f build/fder          /usr/local/bin/
    cp -f build/deployment    /usr/local/bin/
    echo "已安装至[/usr/local/bin/]"
elif [[ $1 == "uninstall" || $1 == "remove" ]];then
    checkBuild
    rm -f /usr/local/bin/fder
    rm -f /usr/local/bin/deployment
    echo "从[/usr/local/bin/]中移除"
elif [[ $1 == "clear" || $1 == "clean" ]];then
    rm build/* -rf
    echo "已清除"
fi